package com.ccys.app.service.impl;

import com.ccys.db.page.AppPageDto;
import com.ccys.app.service.HistoryScreenService;
import com.ccys.common.vo.ResponseResultApp;
import com.ccys.db.mapper.TblBookingMapper;
import com.ccys.db.mapper.TblMemberMapper;
import com.ccys.db.vo.app.historyScreen.GetBookingHistoryVo;
import com.ccys.db.vo.app.historyScreen.MemberBookingMakeVo;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: WhiteCoat
 * @description: 用户查看问诊记录接口
 * @author: ZhangJingCan
 * @create: 2024-01-28 16:17
 **/

@Service
public class HistoryScreenServiceImpl implements HistoryScreenService {

    /**
     * 用户表
     */
    @Resource
    private TblMemberMapper tblMemberMapper;

    @Resource
    private TblBookingMapper tblBookingMapper;

    @Override
    public ResponseResultApp<GetBookingHistoryVo> getBookingHistory(Integer pageIndex, Integer pageSize, String memberId) {
        //最终返回的数据
        GetBookingHistoryVo vo = new GetBookingHistoryVo();
        //开启分页
        AppPageDto.startPage();
        List<MemberBookingMakeVo> list = tblBookingMapper.findPageByMemberId(pageIndex, pageSize, memberId);
        PageInfo<MemberBookingMakeVo> pageInfo = new PageInfo<>(list);
        //循环数据需要设置很多东西
        for (MemberBookingMakeVo makeVo : list) {
            //数据总条数 - 不是分页的总条数
            makeVo.setTotalRecord(pageInfo.getTotal());
            //其余字段 todo 暂时待定 - 比如时间 - 比如有些字段被删除了，现在还没增加到表内

        }
        //设置总页数
        vo.setTotalPage(pageInfo.getPages());
        //设置数据
        vo.setBookings(list);
        return ResponseResultApp.success(vo);
    }
}
